<template>
  <el-dialog :visible.sync="isShow" title="分配角色" @close="close">
    <el-checkbox-group v-model="checkRoles">
      <el-checkbox v-for="i in roles" :key="i.id" :label="i.id">
        {{ i.name }}
      </el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div style="text-align: center">
        <el-button type="primary" @click="submit">提交</el-button>
        <el-button @click="close">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { sysRole } from '@/api/setting.js'
import { sysUser } from '@/api/user.js'
import { sysUserAssignRoles } from '@/api/employees.js'
export default {
  name: 'AssignRole',
  data() {
    return {
      isShow: false,
      checkRoles: [],
      roles: [],
      userId: ''
    }
  },
  created() {
    this.getRoles()
  },
  methods: {
    // 关闭弹窗
    close() {
      this.isShow = false
      this.checkRoles = []
    },
    // 获取所有角色列表
    async getRoles() {
      const res = await sysRole()
      this.roles = res.data.rows
    },
    // 获取员工基本信息
    async getUserInfo(id) {
      this.userId = id
      const res = await sysUser(id)
      this.checkRoles = res.data.roleIds
    },
    // 提交点击
    async submit() {
      await sysUserAssignRoles(this.userId, this.checkRoles)
      this.$message.success('分配角色成功')
      this.isShow = false
    }
  }
}
</script>

<style></style>
